import pandas as pd
import numpy as np

data = {'A': ['x', 'y', 'z'], 'B': [1000, 2000, 3000], 'C': [10, 20, 30]}
df = pd.DataFrame(data, index=['a', 'b', 'c'])
print(df)
print(df.values)
print(df.index)
print(df.columns)
df = pd.DataFrame(data, columns=['C', 'B', 'A'], index=['a', 'b', 'c'])
print(df)
# 增加D列
df['D'] = [10, 20, 30]
print(df)
# 删除D列
del df['D']
print(df)
# 增加d的索引行
df.loc['d'] = ['new2', 5000, 50]
print(df)
# 新建一个df
df2 = pd.DataFrame([1, 2, 3, 4, 5], index=['a', 'b', 'c', 'd', 'z'], columns=['E'])
print(df2)
# 两个df进行join
df = df.join(df2, how='outer')
print(df)
# 删除z行
df = df.drop('z')
print(df)
dates = pd.date_range('20250805', periods=8)
print(dates)
# dates = pd.date_range('20250805', '20250814')
# print(dates)
# dates = pd.date_range(end='20250805', periods=20)
# print(dates)
df = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=list('ABCD'))
print(df)
